package com.token.sysorg.services;

import com.token.sql.IntegrateSql;
import com.token.sysorg.bean.FSysDepartment;
import com.token.sysorg.bean.FSysPersonnel;
import com.token.sysorg.bean.FSysUnit;

import java.util.Vector;

import com.token.base.FuncUtil;
import com.token.base.JsonGenerator;
import com.token.base.Pl;
/**
 * 写组织架构-角色
 * @author 代码创建
 */
public class getOrgName_ByID{

	public void getOrgName(FuncUtil F,IntegrateSql iSql) throws Exception {
		String num = F.getUrlQueryString("number", true, "number");
		if("C".equals(num.substring(0, 1).toUpperCase())){
			getComData(num, F, iSql);
		}else if("D".equals(num.substring(0, 1).toUpperCase())){
			getDeptData(num, F, iSql);
		}else{
			getPersonData(num, F, iSql);
		}
	}

	/**
	 * 根据公司编号查询公司信息
	 * @param num
	 * @param F
	 * @param iSql
	 * @throws Exception
	 */
	private void getComData(String num, FuncUtil F, IntegrateSql iSql) throws Exception{
		FSysUnit dao = new FSysUnit(iSql);
		Vector<String> keyValue = new Vector<String>();
		keyValue.add(F.getUrlQueryString(dao.getKeyName()));
		keyValue.add(Pl.getSysId()+"");
		dao.initParamToRs("UnitID=? and SysID=?", keyValue);
		F.putJsonData("data", JsonGenerator.toJson(dao));
		F.putJsonData(dao.getKeyName(), dao.getKeyId());
	}

	/**
	 * 根据部门编号查询部门信息
	 * @param num
	 * @param F
	 * @param iSql
	 * @throws Exception
	 */
	private void getDeptData(String num, FuncUtil F,IntegrateSql iSql) throws Exception {
		FSysDepartment dao = new FSysDepartment(iSql);
		Vector<String> keyValue = new Vector<String>();
		keyValue.add(num);
		keyValue.add(Pl.getSysId()+"");
		dao.initParamToRs("DepartmentNumber=? and SysID=?", keyValue);
		F.putJsonData("data", JsonGenerator.toJson(dao));
		F.putJsonData(dao.getKeyName(), dao.getKeyId());
	}

	/**
	 * 根据人员编号查询人员信息
	 * @param num
	 * @param F
	 * @param iSql
	 * @throws Exception
	 */
	private void getPersonData(String num, FuncUtil F,IntegrateSql iSql) throws Exception {
		FSysPersonnel dao = new FSysPersonnel(iSql);
		Vector<String> keyValue = new Vector<String>();
		keyValue.add(num);
		keyValue.add(Pl.getSysId()+"");
		dao.initParamToRs("PersonNumber=? and SysID=?", keyValue);
		F.putJsonData("data", JsonGenerator.toJson(dao));
		F.putJsonData(dao.getKeyName(), dao.getKeyId());
	}
}
